<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" errorPage="/error.jsp" isELIgnored="false" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://atleap.blandware.com/taglib" prefix="atleap" %>
<html:xhtml />

<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="HTML_TEXT_FIELD_MAX_LENGTH" />
    <c:if test="${requestScope.previewing}">
        <c:set var="author" value="${requestScope.form.authorStr}" />
        <c:if test="${requestScope.fullName != null}">
            <c:set var="author" value="${requestScope.fullName}" />
        </c:if>
        <table border="0" cellpadding="0" cellspacing="0" class="postList" id="postList">
            <tr class="evenPost">
                <td width="20%" valign="top" align="center">
                    <c:out value="${author}" escapeXml="true" />
                </td>
                <td>
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="postInternalTable">
                        <tr>
                            <td class="postTitleCell">
                                <atleap:formatDate value="now" type="datetime" />
                                <strong><atleap:message key="forum.post.form.subject" />:</strong>
                                <c:out value="${requestScope.form.subject}" escapeXml="true" />
                            </td>
                        </tr>
                        <tr>
                            <td class="postInternalCell">
                                ${requestScope.form.body}
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </c:if>

    <table cellpadding="0" cellspacing="0" border="0" class="modificationTable">
        <c:choose>
            <c:when test="${pageContext.request.remoteUser == null}">
                <tr>
                    <th>
                        <atleap:label property="authorStr" key="forum.post.form.authorStr" colon="false" helpTip="true" />
                    </th>
                    <td>
                        <html:text property="authorStr" styleClass="text" maxlength="${pageScope.HTML_TEXT_FIELD_MAX_LENGTH}" />
                    </td>
                </tr>
                <tr>
                    <th>
                        <atleap:label property="emailStr" key="forum.post.form.emailStr" colon="false" helpTip="true" />
                    </th>
                    <td>
                        <html:text property="emailStr" styleClass="text" maxlength="${pageScope.HTML_TEXT_FIELD_MAX_LENGTH}" />
                    </td>
                </tr>
            </c:when>
            <c:otherwise>
                <html:hidden property="authorStr" value="dummy" />
                <html:hidden property="emailStr" value="dummy@dummy.com" />
            </c:otherwise>
        </c:choose>
        <tr>
            <th>
                <atleap:label property="subject" key="forum.post.form.subject" colon="false" helpTip="true" />
            </th>
            <td>
                <html:text property="subject" styleClass="text" maxlength="${pageScope.HTML_TEXT_FIELD_MAX_LENGTH}" />
            </td>
        </tr>
    </table>
    <div class="languageField">
        <atleap:message key="forum.post.form.body" />
    </div>
    <script language="JavaScript" type="text/javascript">
    function syncRTE() {
        if (isRichText) {
            updateRTE('body');
        }
        return true;
    }

    initRTE("${ctxPath}/rte/images/", "${ctxPath}/rte/", "", false);
    </script>
    <script language="JavaScript" type="text/javascript">
    if (isRichText) {
        try {
            writeRichText('body', "${preparedBody}", 400, 200, true, false);
        } catch (e) {
            isRichText = false;
            removeRTEDiv('body');
        }
    }
    if (!isRichText) {
        document.write("<textarea name=\"body\" class=\"forumPost\">${preparedBody}</textarea><br />");
    }
    </script>
    <noscript>
        <textarea name="body" class="forumPost">${requestScope.form.body}</textarea><br />
    </noscript>
    <html:hidden property="uri" value="/forumpost" />
    <atleap:submit styleClass="button"><atleap:message key="core.commons.buttons.create" /></atleap:submit>
    <atleap:submit property="preview" styleClass="button" onclick="createFormElement('input', 'hidden', this.name, this.id, 'true', this.form);bCancel=false;"><atleap:message key="core.commons.buttons.preview" /></atleap:submit>
    <atleap:cancel styleClass="button"><atleap:message key="core.commons.buttons.cancel" /></atleap:cancel>
